package com.siwei.mes.entity.experiment.cement;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

/**
 * @Description: 水泥-凝结时间
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class CementNjsj {
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "凝结时间信息")
    private CementNjsj.Njsj njsj = new CementNjsj.Njsj();
    @ApiModelProperty(value = "结果计算时间")
    private CementNjsj.Jgjs jgjs = new CementNjsj.Jgjs();

    @Data
    @Accessors(chain = true)
    @ApiModel("结果计算时间")
    public static class Jgjs {
        @ApiModelProperty(value = "初凝时间")//1
        private String cnsj = "";
        @ApiModelProperty(value = "初凝单项结论")//1
        private String cnsjjl = "";
        @ApiModelProperty(value = "终凝时间")//1
        private String znsj = "";
        @ApiModelProperty(value = "终凝单项结论")//1
        private String znsjjl = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("凝结时间信息")
    public static class Njsj {
        @ApiModelProperty(value = "加水时间")
        private String jssj = "";
        @ApiModelProperty(value = "下沉深度")
        private String xcsd = "";
        @ApiModelProperty(value = "到达初凝时间")
        private String ddcnsj = "";
        @ApiModelProperty(value = "到达终凝时间")
        private String ddznsj = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        CementNjsj entity = new CementNjsj();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, CementNjsj.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, CementNjsj.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        CementNjsj entity = JsonUtils.getObject(objJson, CementNjsj.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        CementNjsj.Jgjs jgjs = entity.getJgjs();
        if (jgjs == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(jgjs.getCnsj()) || "null".equals(jgjs.getCnsj())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
       /* if (StringUtils.isBlank(jgjs.getCnsjsfhg()) || "null".equals(jgjs.getCnsjsfhg())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        if (StringUtils.isBlank(jgjs.getZnsj()) || "null".equals(jgjs.getZnsj())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(jgjs.getZnsjsfhg()) || "null".equals(jgjs.getZnsjsfhg())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }
}
